home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / wanderer / fall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-26  |  5.1 KB  |  219 lines

  1. #include "wand_head.h"
  2.  
  3. extern void draw_symbol();
  4. extern int debug_disp;
  5. extern char screen[NOOFROWS][ROWLEN+1];
  6.  
  7. int check(mx,my,x,y,dx,dy,sx,sy,howdead)
  8. /* check for any falling caused by something moving out of x,y along
  9.    vector dx,dy. All the others are constant and should really have
  10.    been global...                             */
  11. int x,y,sx,sy,dx,dy, *mx, *my;
  12. char howdead[25];
  13. {
  14. int ret=0;
  15. ret+=fall(mx,my,x,y,sx,sy,howdead);
  16. ret+=fall(mx,my,x-dx,y-dy,sx,sy,howdead);
  17. ret+=fall(mx,my,x-dy,y-dx,sx,sy,howdead);
  18. ret+=fall(mx,my,x+dy,y+dx,sx,sy,howdead);
  19. ret+=fall(mx,my,x-dx-dy,y-dy-dx,sx,sy,howdead);
  20. ret+=fall(mx,my,x-dx+dy,y-dy+dx,sx,sy,howdead);
  21. return ret;
  22. }
  23.  
  24. int fall(mx,my,x,y,sx,sy,howdead)  /* recursive function for falling */
  25.                    /* boulders and arrows */
  26. int  x,y,sx,sy, *mx, *my;
  27. char howdead[25];
  28. {
  29. int nx = x,nyl = y,nyr = y,retval = 0;
  30. if ((y>(NOOFROWS-1))||(y<0)||(x<0)||(x>(ROWLEN-1)))
  31.     return(0);
  32. if((screen[y][x] != 'O') && (screen[y][x] != ' ') && (screen[y][x] != 'M') &&
  33.    (screen[y][x] !='\\') && (screen[y][x] != '/') && (screen[y][x] != '@'))
  34.     return(0);
  35. if(screen[y][x] == 'O')
  36.     {
  37.     if((screen[y][x-1] == ' ') && (screen[y-1][x-1] == ' '))
  38.         nx--;
  39.     else
  40.     {
  41.         if((screen[y][x+1] == ' ') && (screen[y-1][x+1] == ' '))
  42.             nx++;
  43.     else
  44.         nx = -1;
  45.     }
  46.     if((screen[y-1][x] == ' ') && (screen[y-1][x+1] == ' '))
  47.         nyr--;
  48.     else
  49.     {
  50.         if((screen[y+1][x] == ' ') && (screen[y+1][x+1] == ' '))
  51.             nyr++;
  52.     else
  53.         nyr = -1;
  54.     }
  55.     if((screen[y-1][x] == ' ') && (screen[y-1][x-1] == ' '))
  56.         nyl--;
  57.     else
  58.     {
  59.         if((screen[y+1][x] == ' ') && (screen[y+1][x-1] == ' '))
  60.             nyl++;
  61.     else
  62.         nyl = -1;
  63.     }
  64.     }
  65. if(screen[y][x] == '\\')
  66.     {
  67.     if(screen[y-1][++nx] != ' ')
  68.     nx = -1;
  69.     if(screen[--nyr][x+1] != ' ')
  70.         nyr = -1;
  71.     if(screen[++nyl][x-1] != ' ')
  72.         nyl = -1;
  73.     }
  74. if(screen[y][x] == '/')
  75.     {
  76.     if(screen[y-1][--nx] != ' ')
  77.     nx = -1;
  78.     if(screen[++nyr][x+1] != ' ')
  79.     nyr = -1;
  80.     if(screen[--nyl][x-1] != ' ')
  81.     nyl = -1;
  82.     }
  83. if((screen[y][nx] != ' ') && (screen[y][nx] != 'M'))
  84.     nx = -1;
  85. if((screen[y-1][x] == 'O') && (nx >= 0) && (y > 0)) /* boulder falls ? */
  86.     {
  87.     screen[y-1][x] = ' ';
  88.     if(screen[y][nx] == '@')
  89.         {
  90.         strcpy(howdead,"a falling boulder");
  91.         retval=1;
  92.         }
  93.     if(screen[y][nx] == 'M')
  94.         {
  95.         *mx = *my = -2;
  96.     screen[y][nx] = ' ';
  97.         }
  98.     screen[y][nx] = 'O';
  99.     if(!debug_disp)
  100.     {
  101.         if((y<(sy+5)) && (y>(sy-3)) && (x>(sx-6)) && (x<(sx+6)))
  102.             draw_symbol((x-sx+5)*3,(y-sy+2)*2,' ');
  103.         if((y<(sy+4)) && (y>(sy-4)) && (nx>(sx-6)) && (nx<(sx+6)))
  104.             draw_symbol((nx-sx+5)*3,(y-sy+3)*2,'O');
  105.     }
  106.     else
  107.     {
  108.     move(y,x+1);
  109.     addch(' ');;
  110.     move(y+1,nx+1);
  111.     addch('O');
  112.     }
  113.     refresh();
  114.     retval+=fall(mx,my,nx ,y+1,sx,sy,howdead);
  115.     retval+=check(mx,my,x,y-1,0,1,sx,sy,howdead);
  116.     if(screen[y+1][nx] == '@')
  117.         {
  118.         strcpy(howdead,"a falling boulder");
  119.         return(1);
  120.         }
  121.     if(screen[y+1][nx] == 'M')
  122.         {
  123.         *mx = *my = -2;
  124.     screen[y+1][nx] = ' ';
  125.         }
  126.     }
  127. if((screen[nyr][x] != ' ')&&(screen[nyr][x] != 'M'))
  128.     nyr = -1;
  129. if((screen[y][x+1] == '<')&&(nyr>=0)&&(x+1<ROWLEN)) /* arrow moves ( < ) ? */
  130.     {
  131.     screen[y][x+1] = ' ';
  132.     if(screen[nyr][x] == '@')
  133.         {
  134.         strcpy(howdead,"a speeding arrow");
  135.         retval = 1;
  136.         }
  137.     if(screen[nyr][x] == 'M')
  138.         {
  139.         *mx = *my = -2;
  140.     screen[nyr][x] = ' ';
  141.         }
  142.     screen[nyr][x] = '<';
  143.     if(!debug_disp)
  144.     {
  145.         if((y<(sy+4)) && (y>(sy-4)) && (x<(sx+5)) && (x>(sx-7)))
  146.             draw_symbol((x-sx+6)*3,(y-sy+3)*2,' ');
  147.         if((nyr<(sy+4)) && (nyr>(sy-4)) && (x<(sx+6)) && (x>(sx-6)))
  148.             draw_symbol((x-sx+5)*3,(nyr-sy+3)*2,'<');
  149.     }
  150.     else
  151.     {
  152.     move(y+1,x+2);
  153.     addch(' ');
  154.     move(nyr+1,x+1);
  155.     addch('<');
  156.     }
  157.     refresh();
  158.     retval+=fall(mx,my,x-1,nyr,sx,sy,howdead);
  159.     retval+=check(mx,my,x+1,y,-1,0,sx,sy,howdead);
  160.     if(screen[nyr][x-1] == '@')
  161.         {
  162.         strcpy(howdead,"a speeding arrow");
  163.         return(1);
  164.         }
  165.     if(screen[nyr][x-1] == 'M')
  166.         {
  167.         *mx = *my = -2;
  168.     screen[nyr][x-1] = ' ';
  169.         }
  170.     }
  171. if((screen[nyl][x] != ' ')&&(screen[nyl][x] != 'M'))
  172.     nyl = -1;
  173. if((screen[y][x-1] == '>')&&(nyl>=0)&&(x>0))       /* arrow moves ( > ) ? */
  174.     {
  175.     screen[y][x-1] = ' ';
  176.     if(screen[nyl][x] == '@')
  177.         {
  178.         strcpy(howdead,"a speeding arrow");
  179.         retval = 1;
  180.         }
  181.     if(screen[nyl][x] == 'M')
  182.         {
  183.         *mx = *my = -2;
  184.     screen[nyl][x] = ' ';
  185.         }
  186.     screen[nyl][x] = '>';
  187.     if(!debug_disp)
  188.     {
  189.         if((y<(sy+4)) && (y>(sy-4)) && (x<(sx+7)) && (x>(sx-5)))
  190.             draw_symbol((x-sx+4)*3,(y-sy+3)*2,' ');
  191.         if((nyl<(sy+4)) && (nyl>(sy-4)) && (x<(sx+6)) && (x>(sx-6)))
  192.             draw_symbol((x-sx+5)*3,(nyl-sy+3)*2,'>');
  193.     }
  194.     else
  195.     {
  196.     move(y+1,x);
  197.     addch(' ');
  198.     move(nyl+1,x+1);
  199.     addch('>');
  200.     }
  201.     refresh();
  202.     retval+=fall(mx,my,x+1,nyl,sx,sy,howdead);
  203.     retval+=check(mx,my,x-1,y,1,0,sx,sy,howdead);
  204.     if(screen[nyl][x+1] == '@')
  205.         {
  206.         strcpy(howdead,"a speeding arrow");
  207.         return(1);
  208.         }
  209.     if(screen[nyl][x+1] == 'M')
  210.         {
  211.         *mx = *my = -2;
  212.     screen[nyl][x+1] = ' ';
  213.         }
  214.     }
  215. if(retval>0)
  216.     return(1);
  217. return(0);
  218. }
  219.